<template>
	<el-container>
		<el-header>
			<div class="right-panel">
				<div class="right-panel-search">
					<el-input v-model="search.apply_name" placeholder="名称" clearable @keyup.enter="upsearch"></el-input>
                    <el-input v-model="search.search_keyword"  class="input-with-search" style="width: 300px" @keyup.enter="upsearch">
                        <template #prepend>
                            <el-select v-model="search.field" placeholder="请选择" style="width: 110px">
                                <el-option label="联系人" value="linkman"/>
                                <el-option label="联系方式" value="mobile"/>
                            </el-select>
                        </template>
                    </el-input>
					<el-select v-model="search.type" clearable placeholder="供应商分类">
                        <el-option label="供应商" :value="1" />
                        <el-option label="染色厂" :value="2" />
                        <el-option label="加工厂" :value="3" />
                    </el-select>
					<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
					<el-button type="primary" icon="el-icon-refresh" @click="refresh"></el-button>
				</div>
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable ref="table" row-key="id" :apiObj="apiObj" @selection-change="selectionChange" stripe remoteSort remoteFilter border>
				<el-table-column type="selection" width="50" reserve-selection align="center"></el-table-column>
				<el-table-column type="index" label="序号" fixed align="center" width="60"></el-table-column>
                <el-table-column label="名称" prop="" align="center"></el-table-column>
                <el-table-column label="联系人" prop="" align="center"></el-table-column>
                <el-table-column label="联系方式" prop="" align="center"></el-table-column>
                <el-table-column label="类型" prop="" align="center"></el-table-column>
                <el-table-column label="应付金额" prop="" align="center"></el-table-column>
                <el-table-column label="退货金额" prop="" align="center"></el-table-column>
                <el-table-column label="已付金额" prop="" align="center"></el-table-column>
                <el-table-column label="待付金额" prop="" align="center"></el-table-column>
				<el-table-column label="操作" align="center" width="180">
					<template #default="scope">
                        <div class="buttonFlex">
							<el-button type="primary" size="small" @click="table_payment(scope.row, scope.$index)" v-auth="'payment.pay'">付款</el-button>
							<el-button type="success" size="small" @click="table_record(scope.row, scope.$index)" v-auth="'payment.record'">付款记录</el-button>
                        </div>
					</template>
				</el-table-column>
			</scTable>
		</el-main>
	</el-container>
	<save-dialog v-if="dialog.save" ref="saveDialog" @success="handleSuccess" @closed="dialog.save = false"></save-dialog>
    <record-list v-if="dialog.record" ref="recordDialog" @success="handleSuccess" @closed="dialog.record = false"></record-list>
</template>

<script>
import RecordList from '../record/recordList.vue'
import saveDialog from './save'

export default {
	name: '客户列表',
	components: {
		saveDialog, RecordList
	},
	data() {
		return {
			dialog: {
				save: false,
				record: false,
			},
            apiObj: this.$API.ware.ware.summary.list,
			selection: [],
			search: {
                apply_name: null,
                keyword: null,
                field: "linkman",
                type: null,
			},
		}
	},
	mounted() {
	},
	methods: {
		//付款
		table_payment(row) {
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open('edit').setData(row)
			})
		},
        // 付款记录
        table_record(row) {
			this.dialog.record = true
			this.$nextTick(() => {
				this.$refs.recordDialog.open('edit').setData(row)
			})
		},
		//表格选择后回调事件
		selectionChange(selection) {
			this.selection = selection;
		},
		//搜索
		upsearch() {
			this.$refs.table.upData(this.search)
		},
		refresh() {
			for (const key in this.search) {
				this.search[key] = null;
			}
			this.$refs.table.upData(this.search)
		},
		//本地更新数据
		handleSuccess(data, mode) {
			if (mode == 'add') {
				this.$refs.table.refresh()
			} else if (mode == 'edit') {
				this.$refs.table.refresh()
			}
		}
	}
}
</script>

<style></style>
